package com.yuexun.beilunpatient.ui.registration.adapter;

import android.widget.AbsListView;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.ui.registration.bean.AppointmentDepBean;
import com.yuexun.beilunpatient.ui.registration.bean.AppointmentDepData;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.Collection;

/**
 * Created by chenss on 2018/10/29.
 */
public class RegistrationDepAdapter extends KJAdapter<Object> {

    //itemA类的type标志
    private static final int TYPE_A = 0;
    //itemB类的type标志
    private static final int TYPE_B = 1;

    public RegistrationDepAdapter(AbsListView view, Collection<Object> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder helper, Object item, boolean isScrolling, int position) {
        super.convert(helper, item, isScrolling, position);
        TextView tv_dep = helper.getView(R.id.tv_dep);
        int type = getItemViewType(item);
        switch (type) {
            case TYPE_A:
                AppointmentDepBean depBean = (AppointmentDepBean) item;
                tv_dep.setText(depBean.getDepartment_name());
                tv_dep.setBackgroundColor(mCxt.getResources().getColor(R.color.white));
                break;

            case TYPE_B:
                AppointmentDepData depData = (AppointmentDepData) item;
                tv_dep.setText(depData.getDepartment_center_name());
                if(depData.isSelect()){
                    tv_dep.setBackgroundColor(mCxt.getResources().getColor(R.color.white));
                }else{
                    tv_dep.setBackgroundColor(mCxt.getResources().getColor(R.color.bg_color));
                }
                break;
        }

    }

    /**
     * 获得itemView的type
     * @param object
     * @return
     */
    public int getItemViewType(Object object) {
        int result = 0;
        if (object instanceof AppointmentDepBean) {
            result = TYPE_A;
        }
        else if (object instanceof AppointmentDepData) {
            result = TYPE_B;
        }
        return result;
    }
}
